<template>
  <div class="container">

    <my-info-item :content="storeUserInfo.pic" :title="'头像'" @itemData="itemData"/>
    <my-info-item :content="storeUserInfo.nickname"
                  :isEmpty="storeUserInfo.nickname ===''"
                  :title="'昵称'" @itemData="itemData"/>
    <my-info-item :content="storeUserInfo.cardName"
                  :isEmpty="storeUserInfo.cardName ===''"
                  :title="'姓名'" @itemData="itemData"/>
    <my-info-item :content="storeUserInfo.idcard"
                  :isEmpty="storeUserInfo.idcard ===''"
                  :title="'身份证'" @itemData="itemData"/>
    <my-info-item :content="storeUserInfo.sex===2?'女':'男'"
                  :isEmpty="storeUserInfo.sex != 2 && storeUserInfo.sex != 1"
                  :title="'性别'" @itemData="itemData"/>
    <my-info-item :content="storeUserInfo.mobile"
                  :isEmpty="storeUserInfo.mobile ==='00000000000'"
                  :title="'手机'" @itemData="itemData"/>
    <my-info-item :content="storeUserInfo.educational"
                  :isEmpty="storeUserInfo.educational ===''"
                  :title="'学历'" @itemData="itemData"/>
    <my-info-item :content="storeUserInfo.job"
                  :isEmpty="storeUserInfo.job ===''"
                  :title="'职务'" @itemData="itemData"/>
    <my-info-item :content="storeUserInfo.cityname"
                  :isEmpty="storeUserInfo.cityname ===''"
                  :title="'城市'" @itemData="itemData"/>


    <vant-over-lay-bind-mobile :show="show"  @cancelFun="cancelFun"></vant-over-lay-bind-mobile>
    <vant-over-lay-common :getData="sendShowCommonData" :show="showCommon"
                          @showFun="receiveCommonComStatus" @cancelFun="cancelFun"></vant-over-lay-common>

    <picker-gender :title="pickTitle" :index ="pickIndex" :columns="pickData" :show="pickerShow" @pickData="receivePickData"></picker-gender>

  </div>
</template>

<script>
  import MyInfoMixIn from './MyInfoMixIn'
  import {Toast} from 'vant'
  import {userTypes} from '../../../repo/store/user'

  export default {
    mixins: [MyInfoMixIn],
    data () {
      return {
        pickData: [],
        pickTitle: '',
        pickIndex: 0,
        gender: ['男', '女'],
        sendShowCommonData: {},
        nameOrID: {
          title: '姓名,身份证',
          type: 'input',
          placeholder1: '请输入姓名',
          placeholder2: '请输入身份证号码'
        },
      }
    },
    methods: {
      receivePickData (data) {
        this.pickerShow = false
        if (data === '') return
        let sendData = null
        sendData = this.pickData != this.edu ? {sex: data === '男' ? 1 : 2} : {educational: data}
        this.$store.dispatch(userTypes.EDIT_USER_INFO, sendData).then(() => {
          Toast('修改成功')
          this.fetchData()
        })
      },
      itemData (data) {
        if ((data.title === '姓名' && this.storeUserInfo.cardName) || (data.title === '身份证' && this.storeUserInfo.idcard)) {
          Toast('无法修改')
          return
        }
        console.log(data, this.pickerShow)

        switch (data.title) {
          case '头像':
            break
          case '手机':
            this.show = true
            break
          case '性别':
            this.pickerShow = true
            this.pickData = this.gender
            this.pickTitle = data.title
            this.pickIndex = this.storeUserInfo.sex === 2 ? 1 : 0
            break
          case '学历':
            this.pickerShow = true
            this.pickData = this.edu
            this.pickTitle = data.title
            let eduIndex = this.edu.indexOf(this.storeUserInfo.educational)
            this.pickIndex = eduIndex < 0 ? 0 : eduIndex
            break
          case '姓名':
          case '身份证':
            this.sendShowCommonData = this.nameOrID
            this.showCommon = true
            break
          case '昵称':
            this.sendShowCommonData = {
              title: data.title,
              type: 'input_single',
              placeholder1: '请输入' + data.title
            }
            this.showCommon = true
            break
          case '职务':
            this.sendShowCommonData = {
              title: data.title,
              type: 'textarea',
              placeholder1: '请输入' + data.title
            }
            this.showCommon = true
            break
          case '城市':
            this.$_router.push('/edit_city')
            break
          default:
            console.log(data.title)
        }

      },
      receiveCommonComStatus (data, type) {
        if (data === '' || data === false) return
        let sendData = {}
        if (type.type === 'input') {
          this.$store.dispatch(userTypes.EDIT_USER_BIND_CARD_ID, data).then(() => {
            Toast('修改成功')
            this.cancelFun()
            this.fetchData()
          })
        } else {
          sendData = type.title === '职务' ? {job: data} : {nickname: data}
          this.$store.dispatch(userTypes.EDIT_USER_INFO, sendData).then(() => {
            Toast('修改成功')
            this.cancelFun()
            this.fetchData()
          })
        }
      },
    }
  }
</script>

<style scoped>
  .container > div:nth-of-type(5) {
    margin: 10px 0px;
    border-top: 1px #EEEEEE solid;
  }

  .container > div:nth-of-type(6) {
    border-top: 1px #EEEEEE solid;
  }
</style>
